<?php

//session_start(); // prepare use of session variables
//phpinfo();
// Store current page for back tracking
$_SESSION['prev_uri'] = $_SERVER['REQUEST_URI'];

$pid = $_GET[id];

// Establish connection to db
$con = mysqli_connect ( "localhost", "cms", "cms", "cms" );
// Check connection
if (mysqli_connect_errno ()) {
	echo "Failed to connect to MySQL: " . mysqli_connect_error ();
}

$result = mysqli_query ( $con, "SELECT title,content FROM page WHERE id = '$pid'" );

// Get site settings
$settings = mysqli_query ( $con, "SELECT background,sitename FROM configuration" );
$setting = mysqli_fetch_array ( $settings ); // expecting just one row
$background = $setting[background];
$sitename = $setting[sitename];

$row = mysqli_fetch_array ( $result )
?>

<!DOCTYPE html>
<html <?php if ($background) echo "style=\"background: ".$background.";\"" ?>>
<head>
<link rel="stylesheet" type="text/css" href="main.css">
<title>
			<?php
			if ($row [title]) {
				echo $row [title];
			} else {
				echo "Page not found";
			}
			?>
		</title>
</head>
<body <?php if ($background) echo "style=\"background: ".$background.";\"" ?>>
	<div class="topbar" >
		<a href="<?php echo 'admin/edit_page.php?id='.$pid; ?>">Edit page</a>
		<a href="admin">Administration</a>
	</div>
	<div class="content">
		<div class="header">
			<a href="#"><h1><?php echo $sitename?></h1></a>
		</div>
		<div class="topmenu">
			<?php include("topmenu.php");?>
		</div>
		<div class="cols rightmenu">
			<div class="colleft">
				<div class="col1">
					<h2><?php echo $row [title];?></h2>
				<?php
				if ($row [content]) {
					echo $row [content];
				} else {
					echo "Page not found";
				}
				?>
				</div>
				<div class="col2">
					<h2>Column 2</h2>
					<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit...</p>
					<ul>
						<li><a href="#">Link 1</a></li>
						<li><a href="#">Link 2</a></li>
					</ul>
				</div>
			</div>
		</div>
		<div class="footer">
			<p>Footer</p>
		</div>
	</div>
	</body>
</html>